<?php defined('SYSPATH') or die('No direct script access.');

class Date extends Kohana_Date {

    public static function unix2date($time,$part=NULL) {
		if($time == 0){
			return "-";
		}else{
			switch($part){
				case('year'):
					return date('Y', $time);
				break;
				case('month'):
					return date('Y-m', $time);
				break;
				// cała data z godziną
				case('hour'):
					return date('Y-m-d H:i:s', $time);
				break;
				//domyślny wariant $part=NULL - zwraca całość daty (bez godziny)
				default:
					return date('Y-m-d', $time);
				break;
			}
		}
	}
	
	public static function date2unix($str) 
	{
		if($str == ''){
			return null;
			exit;
		}
		if(preg_match('/ /',$str))
		{
			list($date, $time) = explode(' ', $str);
			
		}else{
			$date = $str;
			$time = "00:00:00";
		}
		list($hour, $minute, $second) = explode(':', $time);
		list($year, $month, $day) = explode('-', $date);
		
		$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
		return $timestamp;
	}

	public static function months_conv($input,$lang='pl')
	{
		if($lang == 'pl')
		{
			$pol = array('styczeń ', 'luty ', 'marzec ', 'kwiecień ', 'maj ', 'czerwiec ', 'lipiec ', 'wrzesień ', 'październik ', 'listopad ', 'grudzień ');
			$digit = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
			return $output = str_replace($digit,$pol,$input);
		}
	}
	
	public static function check_span($from,$to)
	{
		//echo time()." - ".$from." - ".$to;
		if($from == 0 || $to == 0){
			return false;
			exit;
		}else{
			$now = time();
			if($now > $from && $now < $to)
			{
				return true;
			}else{
				return false;
			}
		}
	}
}
